<div class="layui-container fly-marginTop">
  <div class="fly-panel fly-panel-user" pad20>
    <div class="layui-tab layui-tab-brief" lay-filter="user">

      <ul class="layui-tab-title">
        <li href="{:url('home/index/login')}">前往登录</li>
        <li class="layui-this">找回密码</li>
      </ul>

      <div class="layui-form layui-tab-content" id="LAY_ucm" style="padding: 20px 0;">
        <div class="layui-tab-item layui-show">
          <div class="layui-form layui-form-pane">
            <form method="post">

              <div class="layui-form-item">
                <label for="L_email" class="layui-form-label">邮箱</label>
                <div class="layui-input-inline">
                  <input type="text" id="L_email" name="email" value="2419498185@qq.com" required lay-verify="required"
                    placeholder="请输入邮箱" autocomplete="off" class="layui-input">
                </div>
              </div>

              <div class="layui-form-item">
                <label for="L_nickname" class="layui-form-label">昵称</label>
                <div class="layui-input-inline">
                  <input type="text" id="L_nickname" name="nickname" required lay-verify="required" placeholder="请输入昵称"
                    autocomplete="off" class="layui-input">
                </div>
              </div>

              <div class="layui-form-item">
                <label for="L_vercode" class="layui-form-label">验证码</label>
                <div class="layui-input-inline">
                  <input type="text" id="L_vercode" name="vercode" required lay-verify="required" placeholder="请输入验证码"
                    autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid" style="padding: 0 !important;display: block;">
                  <img src="{:url('home/index/captcha')}" alt="" class="imgCode">
                  <p onclick="changeCode()"
                    style="text-decoration: underline;color: blue;cursor: pointer;user-select: none;">
                    看不清，点击这里换一张</p>
                </div>
              </div>

              <div class="layui-form-item">
                <button class="layui-btn" type="button" id="auth">立即验证</button>
              </div>
            </form>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
<script>
  // 点击切换验证码图片
  function changeCode() {
    document.querySelector(".imgCode").setAttribute('src', `{:url('home/index/captcha')}`)
  }

  layui.use('layer', function () {
    var layer = layui.layer
    var $ = layui.jquery

    // 验证邮箱操作
    // 验证邮箱操作
    $("#auth").on("click", function () {
      var email = $("#L_email").val();
      var nickname = $("#L_nickname").val();
      var code = $("#L_vercode").val();

      if (confirm("确定要发送邮箱！")) {
        $.ajax({
          type: "POST",
          url: `{:url('home/index/fgwemail')}`,
          data: {
            email: email,
            nickname: nickname,
            code: code,
          },
          success: function (data) {

            if (data.result) {
              // 成功
              layer.msg(data.msg, {
                icon: 1,
                time: 2000,
              }, function () {
                // 收藏成功刷新界面
                window.location.href = "{:url('home/index/login')}";
              })
            } else {
              // 失败
              layer.msg(data.msg);
            }

          }
        })
      }
    })


  })
</script>